package Text3;

import java.util.*;
public class Main {
    public static int N = 100010, n, m, idx;
    public static int[] h = new int[N];
    public static int[] e = new int[N];
    public static int[] ne = new int[N];
    public static int[] w = new int[N];
    public static int[] d = new int[N];
    public static int[] cnt = new int[N]; //存多少边
    public static boolean[] st = new boolean[N];

    private static void add(int a, int b, int c) {
        e[idx] = b;
        ne[idx] = h[a];
        w[idx] = c;
        h[a] = idx++;
    }

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        n = scanner.nextInt();
        m = scanner.nextInt();
        Arrays.fill(h, -1);
        d[1] = 0;
        for (int i = 0; i < m; i++) {
            int a = scanner.nextInt();
            int b = scanner.nextInt();
            int c = scanner.nextInt();
            add(a, b, c);
        }
        if(spfa()){
            System.out.println("Yes");
        } else {
            System.out.println("No");
        }
    }

    private static boolean spfa() {
        Queue<Integer> q = new LinkedList<Integer>();
        for (int i = 1; i <= n; i++) {
            q.offer(i);
            st[i] = true;
        }
        while (!q.isEmpty()) {
            int t = q.poll();
            st[t] = false;
            for (int i = h[t]; i != -1; i = ne[i]) {
                int j = e[i];
                if (d[j] > d[t] + w[i]) {
                    d[j] = d[t] + w[i];
                    cnt[j]=cnt[t]+1;
                    if(cnt[j]>=n){
                        return true;
                    }
                    if(!st[j]){
                        q.offer(j);
                        st[j]=true;
                    }
                }
            }

        }
       return false;
    }
}
